package Metier;

import java.sql.*;

import javax.servlet.ServletException;

public class Bdd implements I_Bdd {

	private String url = "jdbc:mysql://localhost:3306/planning";
	private String user = "planning";
	private String password = "mdp_planning";
	private Connection con;
	private Statement stmt;

	public Bdd() throws SQLException, ServletException {
//		try {
//			Class.forName("com.mysql.jdbc.Driver");
//		} catch (ClassNotFoundException e) {
//			throw new ServletException();
//		}
		Driver monDriver = new com.mysql.jdbc.Driver();
		DriverManager.registerDriver(monDriver);
		con =DriverManager.getConnection (url, user, password);
		stmt = con.createStatement();
	}
	/* (non-Javadoc)
	 * @see Metier.I_Bdd#update(java.lang.String)
	 */
	@Override
	public int update(String sql) throws SQLException{
		return stmt.executeUpdate(sql);
	}
	/* (non-Javadoc)
	 * @see Metier.I_Bdd#select(java.lang.String)
	 */
	@Override
	public ResultSet select(String sql) throws SQLException{
		stmt.executeQuery(sql);
		return stmt.getResultSet();
	}
	/* (non-Javadoc)
	 * @see Metier.I_Bdd#closeSt()
	 */
	@Override
	public void closeSt() throws SQLException{
		stmt.close();
	}
	/* (non-Javadoc)
	 * @see Metier.I_Bdd#closeBdd()
	 */
	@Override
	public void closeBdd() throws SQLException{
		con.close();
	}
}
